import java.util.*;

public class Test3 {
    public static void main(String[] args) {
        Stack<Character> stack=new Stack<Character>();
      Queue<Character> queue=new LinkedList<Character>() {
      };
        Scanner sc=new Scanner(System.in);
        String str=sc.nextLine();
        String[] scc=str.split(" ");
        str=scc[0];
        char c = Character.valueOf(scc[1].charAt(0));
        for (int i = 0; i < str.length(); i++) {
           stack.push(str.charAt(i));
        }
        System.out.println(stack.size()+" "+stack.peek());
        int ab=stack.size();
        for (int i = 0; i < ab; i++) {
            System.out.print(stack.pop());
        }
        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }
        for (int i = 0; i < ab; i++) {
            char ch=stack.pop();
            if(ch!=c)
            {
            queue.offer(ch);}
        }
        System.out.println();
        char ca=queue.peek();
        int b=queue.size();
        for (int i = 0; i < b-1; i++) {
            queue.poll();
        }
        System.out.println(b+" "+ca+" "+ queue.poll());
        for (int i = 0; i < str.length(); i++) {
            stack.push(str.charAt(i));
        }
        for (int i = 0; i < ab; i++) {
            char ch=stack.pop();
            if(ch!=c)
            {
                queue.offer(ch);}
        }
        for (int i = 0; i < b; i++) {
            System.out.print(queue.poll());
        }
    }
}
